//统一错误处理器
// middleware/errorHandler.js
module.exports = (err, req, res, next) => {
    console.error(`[${new Date().toISOString()}] 错误:`, err);
  
    const statusCode = err.statusCode || 500;
    const response = {
      error: '服务器错误',
      message: process.env.NODE_ENV === 'development' ? err.message : undefined
    };
  
    res.status(statusCode).json(response);
  };